home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / Documentation / Engineering Notes / Views / Printing < prev    next >
Encoding:
Text File  |  1996-04-26  |  7.5 KB  |  138 lines  |  [TEXT/ttxt]

  1. OpenDoc
  2. Development
  3. Framework
  4.                                                                                                                                                                                      
  5. Adding Printing to ODF Parts 
  6. ODF Release 1                                                                                                                                                             
  7.  
  8.  
  9.  
  10. Table of Contents
  11. ----------------------
  12. • Abstract
  13. • Why You Need to Do Anything at All
  14. • Overview
  15. • Printing Classes
  16. • Basic Printing
  17.     • Changes to Your Root Frame Class
  18.     • Linking with QuickDrawGXLib 
  19.     • Adding a Progress Dialog
  20.     • Determing if Drawing to the Screen or Printing
  21. • Advanced Printing
  22.     • Subclassing FW_CPrintHandler
  23.     • Using a Separate View for Printing
  24.     • Modifying Print Dialogs
  25.  
  26.  
  27. Abstract
  28.  
  29. For various reasons noted below, printing is not enabled by default for all ODF parts.  This document describes how to add printing to your ODF part if you decide to support printing.   See also the Draw and Form samples where printing is implemented.
  30.  
  31.  
  32.  
  33. Why You Need to Do Anything at All
  34.  
  35. Here are the reasons why printing is not enabled by default.  There are parts for which it does not make sense to print; ODFClock and ODFButton are two examples.  A part that doesn’t print should not pay the price (in code size) for a feature it doesn’t use.  Putting printing code directly into FW_CPart or FW_CFrame would make it very difficult to take advantage of code deadstripping.
  36.  
  37. Note that only the topmost part in a document needs to support printing. Naturally you would want ODFClock or ODFButton to print if they are part of another document.  If their container part supports printing, they will get printed as well.  Thus, you only need to support printing if you expect your part to be used outside of a printing embedding part.
  38.  
  39. Overview
  40.  
  41. In ODF/OpenDoc, it is frames that are printed.  Frames print by drawing to a special facet, which is created for them by the printing code.  On the Macintosh, ODF printing supports Quickdraw GX and Quickdraw, both in the same print job.  This is so that if you have embedded GX and non-GX parts, they all print on the same piece of paper, in the same print job.
  42.  
  43.  
  44. Printing Classes
  45.  
  46. FW_CPrintInfo
  47. This class, defined in FWPrInfo.h, encapsulates print/page setup information: printer name, number of copies to print, page boundaries, etc.  It contains methods to get to the platform data structures (gxJob, THPrint on the Mac, PRINTDLG on Windows).
  48.  
  49. FW_CPrintEnvironment
  50. This class, defined in FWPrInfo.h, makes sure that whenever ODF makes printing calls, the Macintosh print driver will be  open.  Constructors in some printing classes take a reference to this class.  On Windows and under Quickdraw GX, this class does nothing.
  51.  
  52. FW_CPrintJob
  53. This class, defined in FWPrInfo.h, encapsulates a running platform print job.  There are calls to open/close the document and pages, and to handle printing errors.
  54.  
  55. FW_CPrintHandler
  56. This class, defined in FWPrHdlr.h, contains all the logic necessary to handle page setup and actual printing.  It interacts with the part, the frame, and other print classes to produce a printed image of the frame.
  57.  
  58. Basic Printing
  59.  
  60. Changes to Your Root Frame Class
  61.  
  62. The only change necessary to activate the Print menu commands and support basic printing of the current frame is to override FW_CFrame::NewPrintHandler and add the following code:
  63.  
  64.     FW_CPrintHandler* CMyFrame::NewPrintHandler(Environment* ev)
  65.     {
  66.         FW_CPart* part = GetPart(ev);
  67.         return new FW_CPrintHandler(part, this);        // print handler base class
  68.     }
  69.  
  70. ODF uses the content view's extent to determine how much to print.  
  71.  
  72. If your frame is only printable some of the time, depending on the content, you should subclass FW_CPrintHandler and override IsCurrentlyPrintable and return TRUE only if your frame can be printed at the time.  For example, the ODFDraw sample part only prints when there is at least one shape in the drawing.
  73.  
  74.     FW_CPrintHandler* CMyFrame::NewPrintHandler(Environment* ev)
  75.     {
  76.         FW_CPart* part = GetPart(ev);
  77.         return new CMyPrintHandler(part, this);            // custom print handler
  78.     }
  79.  
  80.  
  81. Linking with QuickDrawGXLib
  82.  
  83. On the Macintosh, you should link with QuickDrawGXLib in order to support QuickDraw GX printing.  Make sure that you use a “weak” reference, so your part runs even when Quickdraw GX is not installed (in which case only standard printing is supported).
  84.  
  85.  
  86. Adding a Progress Dialog
  87.  
  88. On the Macintosh you can add a standard "progress dialog" with a Cancel button that will be displayed while the print job is being executed.  This is only useful for non-background printing since a background print job can be controlled directly in the Print Manager window.
  89.  
  90. To add the progress dialog simply add the following resource file to your project: 
  91.  
  92.   ODF:Framewrk:FWPart:Other:FWPrint.r
  93.  
  94.  
  95. Determining if Drawing to the Screen or Printing
  96.  
  97. Often you will want to draw your frame slightly differently when you print.  For example, it usually doesn’t make sense to print grid lines and such.  To help you decide how to draw, you can check the facet’s canvas for a platform print job, and/or check if the facet is dynamic.  For example:
  98.  
  99. void CMyView::Draw(Environment*    ev, ODFacet*        odFacet, ODShape*        invalidShape)
  100. {
  101.     ODCanvas* canvas = odFacet->GetCanvas(ev);
  102.  
  103.     FW_Boolean isPrintOrPrintPreview = !canvas->IsDynamic(ev);
  104.     FW_Boolean isPrinting;
  105. #ifdef FW_BUILD_WIN
  106.     isPrinting = canvas->HasPlatformPrintJob(ev, kODWindows);
  107. #endif
  108. #ifdef FW_BUILD_MAC
  109.     isPrinting = canvas->HasPlatformPrintJob(ev, kODQuickDraw) ||
  110.         canvas->HasPlatformPrintJob(ev, kODQuickDrawGX);
  111. #endif
  112. }
  113.  
  114. Note that for the Macintosh, the code checks for both Quickdraw GX and Quickdraw print jobs.  This is because ODF will use a Quickdraw GX print job whenever possible and resort to Print Manager calls only when GX is not available.
  115.  
  116.  
  117. Advanced Printing
  118.  
  119. Subclassing FW_CPrintHandler
  120.  
  121. If you want to change some aspects of ODF printing,  you will need to subclass FW_CPrintHandler, override the appropriate methods, and create an instance of this subclass in your frame's NewPrintHandler method.
  122.  
  123. Using a Separate View for Printing
  124.  
  125. Some parts may want to use a completely different layout when printing.  For example, it doesn’t make sense to print scroll bars, and removing them may affect where embedded frames are positioned.  ODF provides hooks so that you can create a special view that will be printed.  This special view, knowing that it is created specifically for printing, can create a different layout that will then be printed.
  126.  
  127. To accomplish this, you need to override the CreatePrintView and ReleasePrintView methods, and do your layout negotiation in CountPrintPages.
  128.  
  129. Modifying Print Dialogs
  130.  
  131. Some parts may want to change the default print dialogs used by ODF (which just makes the most basic platform calls).   To do this, you can override DoPageSetupDialog and DoJobDialog.
  132. To change the way the user is notified of a printing error or that printing has been cancelled, override NotifyNoDefaultPrinter and NotifyPrintingCanceled.
  133.  
  134. You can also override the print progress dialog.  To do this, you should override CreateProgressDialog, UpdateProgressDialog and DestroyProgressDialog.   If you do this, you are also responsible for implementing an abort/idle proc and setting it in the print job (using SetAbortProc(hDC...) on Windows or pIdleProc on the Macintosh).
  135.  
  136.  
  137. © 1993 - 1996 Apple Computer, Inc. All rights reserved.
  138. Apple, the Apple Logo, Macintosh, and OpenDoc are trademarks of Apple Computer, Inc., registered in the United States and other countries.